#pragma once

#include "PreviewBase.h"
#include "ISinglePreview.h"
#include "SinglePreviewRenderer.h"

ref class SinglePreview sealed :
public NiklasKarl::WarpCam::Native::ISinglePreview,
public PreviewBase
{
public:
	SinglePreview();

	// ISinglePreview
	virtual Windows::Phone::Graphics::Interop::IDrawingSurfaceBackgroundContentProvider^ CreateContentProvider();

	property Windows::Foundation::Size Resolution
	{
		virtual Windows::Foundation::Size get();
		virtual void set(Windows::Foundation::Size size);
	}

	property Nokia::Graphics::Imaging::IImageProvider^ PreviewSource
	{
		virtual Nokia::Graphics::Imaging::IImageProvider^ get();
		virtual void set(Nokia::Graphics::Imaging::IImageProvider^ source);
	}

	property Nokia::Graphics::Imaging::Rotation PreviewRotation
	{
		virtual Nokia::Graphics::Imaging::Rotation get();
		virtual void set(Nokia::Graphics::Imaging::Rotation rotation);
	}
	property Nokia::Graphics::Imaging::FlipMode PreviewFlip
	{
		virtual Nokia::Graphics::Imaging::FlipMode get();
		virtual void set(Nokia::Graphics::Imaging::FlipMode mode);
	}

	property Windows::Foundation::Rect PreviewRect
	{
		virtual Windows::Foundation::Rect get();
		virtual void set(Windows::Foundation::Rect rect);
	}

	property Windows::UI::Color Background
	{
		virtual Windows::UI::Color get();
		virtual void set(Windows::UI::Color color);
	}

	// IDrawingSurfaceManipulationHandler
	virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);

internal:
	// PreviewBase
	virtual HRESULT Connect(IDrawingSurfaceRuntimeHostNative* host, ID3D11Device1* device) override;
	virtual void Disconnect() override;

	virtual HRESULT PrepareResources(const LARGE_INTEGER* presentTargetTime, DrawingSurfaceSizeF* desiredRenderTargetSize) override;
	virtual HRESULT Draw(ID3D11Device1* device, ID3D11DeviceContext1* context, ID3D11RenderTargetView* renderTargetView) override;

private:
	Windows::Foundation::Size m_resolution;

	Nokia::Graphics::Imaging::IImageProvider^ m_source;

	Nokia::Graphics::Imaging::Rotation m_rotation;
	Nokia::Graphics::Imaging::FlipMode m_flip;

	Windows::Foundation::Rect m_rect;

	SinglePreviewRenderer^ m_renderer;

	BOOL m_propertyChanged;
	FLOAT m_background[4];
};